package org.jsbd.boss.task;

import org.jsbd.boss.service.IFileUploadService;
import org.jsbd.boss.util.SpringContextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;

/**
 * @desc
 * @Date 2018/10/18 16:09
 * @Author xupengcheng [xupengcheng@zhexinit.com]
 */
public class FileUploadTask implements Runnable, Serializable {

    public static final Logger logger = LoggerFactory.getLogger(FileUploadTask.class);
    private static final long serialVersionUID = 1L;
    private byte[] datas;
    private String fileName;
    private String objectName;
    private String md5;
    private String bucketName;

    public FileUploadTask(byte[] datas, String bucketName, String objectName, String fileName, String md5) {
        this.datas = datas;
        this.fileName = fileName;
        this.objectName = objectName;
        this.md5 = md5;
        this.bucketName = bucketName;
    }

    @Override
    public void run() {
        long startTime = System.currentTimeMillis();
        SpringContextUtils.getBean(IFileUploadService.class).uploadFile(datas, bucketName, objectName, fileName, md5);
        long costTime = System.currentTimeMillis() - startTime;
        if (costTime > 1000) {
            logger.info("objectName is [{}],costTime is [{}]", new Object[]{objectName, costTime});
        }
    }
}
